package org.sn.spring.springboot.service.impl;

import org.sn.spring.springboot.dao.DemoDao;
import org.sn.spring.springboot.entity.Demo;
import org.sn.spring.springboot.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DemoServiceImpl implements DemoService {

	@Autowired
	private DemoDao demoDao;

	@Override
	public String sayHello(String name) {
		String id = "demo";
		Demo demo = demoDao.selectByPrimaryKey(id);
		if (demo == null) {
			demo = new Demo();
			demo.setId(id);
			demo.setName(name);
			demoDao.insert(demo);
			return demoDao.selectByPrimaryKey(id).getName();
		}
		return name;
	}

}
